package com.ebupt.migu.music.label.controller;

import com.ebupt.migu.common.pojo.MusicRuleRequestBean;
import com.ebupt.migu.music.common.entity.ResultObject;
import com.ebupt.migu.music.label.entity.LabelCustomerDetailRequestBean;
import com.ebupt.migu.music.label.entity.LabelCustomerRequestBean;
import com.ebupt.migu.music.label.entity.LabelCustomerResponseBean;
import com.ebupt.migu.music.label.service.LabelCustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 统一标签服务平台接口
 * @author: liuyangyang@ebupt.com
 * @date: 2021/8/12 14:18
 */
@Slf4j
@RestController
@RequestMapping("/customer")
public class LabelCustomerController {
    @Autowired
    private LabelCustomerService service;

    /**
     * 判定当前客群是否需要将结果数据导入Redis
     *
     * @param groupId
     * @return
     */
    @RequestMapping("/dynamic/only")
    public ResultObject dynamicOnly(@RequestParam("customerId") String groupId) {
//        return service.dynamicOnly(groupId);
        return service.dynamicAndStaticStatus(groupId);
    }

    /**
     * 动态标签客群完成，更新状态
     *
     * @param bean
     * @return
     */
    @RequestMapping("/dynamic/status")
    public LabelCustomerResponseBean dynamicCustomerStatus(@RequestBody LabelCustomerRequestBean bean) {
        log.info("动态更新客群状态:{}", bean.toString());
        return service.updateLabelCustomerStatus(bean, "dynamic");
    }

    /**
     * 统一标签服务客群完成，更新状态
     *
     * @param bean
     * @return
     */
    @RequestMapping(value = "/status")
    public LabelCustomerResponseBean staticCustomerStatus(@RequestBody LabelCustomerRequestBean bean) {
        log.info("静态更新客群状态:{}", bean.toString());
        return service.updateLabelCustomerStatus(bean, "static");
    }



    /**
     * 静态标签规则上报
     *
     * @param bean
     * @return
     */
    @RequestMapping(value = "/detail")
    public LabelCustomerResponseBean detail(@RequestBody LabelCustomerDetailRequestBean bean) {
        return service.detail(bean);
    }

    /**
     * 文件上传至统一标签服务平台
     *
     * @param bean
     * @return
     */
    @RequestMapping("/file/trans")
    public LabelCustomerResponseBean fileTransByManual(@RequestBody MusicRuleRequestBean bean) {
        return service.fileTransByManual(bean);
    }

    /**
     * 客群重组状态上报
     *
     * @param groupId
     * @return
     */
    @RequestMapping("/merge")
    public LabelCustomerResponseBean customerMerge(@RequestParam("customerId") String groupId) {
        log.info("merge customerId:{}", groupId);
        return service.customerMerge(groupId);
    }
}
